package com.miao.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.miao.common.entity.pojo.Product;
import com.miao.shop.dao.ShopProductDao;
import com.miao.shop.service.ShopIndexService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author MiaoWenqing
 * @description: 首页服务层 实现
 * @date 2021/2/19 21:01
 */
@Service
public class ShopIndexServiceImpl implements ShopIndexService {

    @Resource
    private ShopProductDao shopProductDao;





    @Override
    public List<Map<String, Object>> getCategory() {
        ArrayList<Map<String, Object>> maps = new ArrayList<>();



        String[][] headers = new String[][]{
                {"饼干","糖果","巧克力","薯片"},
                {"方便面","粉丝米线","熟食","火腿肠"},
                {"白酒","红酒","红酒","果酒"},
                {"酸奶","纯牛奶","碳酸饮料","冰淇淋"},
                {"樱桃车厘子","草莓","橙子"},
                {"猪肉","羊肉","牛肉","鸡肉"},
                {"鸭蛋","鸡蛋"},
                {"虾","鱼","螃"},
                {"葱姜蒜","白菜","包菜","辣椒"},
        };
        String[] title = new String[]{
                "零食","方便速食","名酒","乳饮冰","水果","肉类","蛋类","海鲜","蔬菜"
        };


        for (int i = 1; i < 10; i++) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("title",title[i-1]);
            map.put("classId",i+"0000");
            map.put("header" ,headers[i-1]);
            ArrayList<Map<String,Object>> productVOS = new ArrayList<>();
            QueryWrapper<Product> productQueryWrapper = new QueryWrapper<>();
            productQueryWrapper.likeRight("pro_class",i);
            List<Product> products = this.shopProductDao.selectList(productQueryWrapper);
            for (int j = 0; j < products.size()&&j<9; j++) {

                HashMap<String, Object> pro = new HashMap<>();

                Product product = products.get(j);
                pro.put("id",product.getProId());
                pro.put("name",product.getProName());
                pro.put("icon",product.getProIcon());
                productVOS.add(pro);
            }
            map.put("pro",productVOS);
            maps.add(map);
        }




        return maps;
    }
}
